#include "adalog/appender/FileAppender.h"
#include "adalog/LogAppender.h"
#include "adalog/LogFormatter.h"
#include "adalog/Logger.h"

namespace adalog 
{
    FileAppender::FileAppender(const std::filesystem::path& file_path)
        : file_path_(file_path)
    {
        os_.open(file_path_, std::ios::app);
        if (!os_.is_open())
        {
            ADALOG_DEFAULT_ERROR("Can not open file: " + file_path_.string());
        }
    }

    FileAppender::~FileAppender()
    {
        if (os_.is_open())
            os_.close();
    }

    void FileAppender::Append(const char* data, size_t len)
    {
        if (!os_.is_open())
        {
            ADALOG_DEFAULT_ERROR("Can not open file: " + file_path_.string());
            return;
        }
        os_.write(data, len);
    }
}